package com.ruoyi.htzj.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.htzj.domain.HtzjScanRecords;
import com.ruoyi.htzj.service.HtzjScanRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/htzj/scanRecords")
public class ScanRecordsController {

    @Autowired
    private HtzjScanRecordsService htzjScanRecordsService;

    /**
     * 分页列表查询
     * @param scanRecords 查询条件
     * @param pageQuery 分页信息
     * @return 分页结果
     */
    @SaCheckPermission("htzj:scanRecords:list")
    @GetMapping("/list")
    public TableDataInfo<HtzjScanRecords> list(HtzjScanRecords scanRecords, PageQuery pageQuery) {
        return htzjScanRecordsService.queryPageList(scanRecords, pageQuery);
    }

    /**
     * 通过 street_id 统计数量
     * @param streetId 街道 ID
     * @return 统计结果
     */
    @SaCheckPermission("htzj:scanRecords:count")
    @GetMapping("/countByStreetId/{streetId}")
    public R<Integer> countByStreetId(@PathVariable Integer streetId) {
        Integer count = htzjScanRecordsService.countByStreetId(streetId);
        return R.ok(count);
    }

    /**
     * 添加扫码记录
     * @param streetId 街道 ID
     * @return 操作结果
     */
    @SaIgnore
    @GetMapping("/add/{streetId}")
    public R<String> add(@PathVariable Integer streetId) {
         return htzjScanRecordsService.addScanRecord(streetId);
    }
}
